package veterinaria.servlet.medicamento;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import veterinaria.excepcion.DAOExcepcion;
import veterinaria.negocio.GestionMedicamentos;

/**
 * Servlet implementation class for Servlet: MedicamentoModificarServlet
 * 
 */
@WebServlet("/MedicamentoModificarServlet")
public class MedicamentoModificarServlet extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet {
	static final long serialVersionUID = 1L;

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public MedicamentoModificarServlet() {
		super();
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
	 * HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
	 * HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int 	v0 = Integer.parseInt(request.getParameter("codigo"));
		String 	v1 = request.getParameter("nombre");
		Double 	v2 = Double.parseDouble(request.getParameter("precio"));
		int 	v3 = Integer.parseInt(request.getParameter("cantidad"));
		String 	v4 = request.getParameter("descripcion");

		GestionMedicamentos negocio = new GestionMedicamentos();
		try {
			negocio.actualizar(v0,v1,v2,v3,v4);
			response.sendRedirect(request.getContextPath()	+ "/MedicamentoBuscarServlet");
		} catch (DAOExcepcion e) {
			System.out.println(e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
	}
}